package com.m2bshop.shop.service.BMCService.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.m2bshop.shop.dao.BMCgoodsDao;
import com.m2bshop.shop.pojo.BMCgoods;
import com.m2bshop.shop.pojo.good_category;
import com.m2bshop.shop.pojo.good_imgs;
import com.m2bshop.shop.service.BMCService.BMCgoodsService;
import com.m2bshop.shop.service.BMCService.GoodcategoryService;
import com.m2bshop.shop.service.BMCService.GoodimgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author zhangyu
 * @create 2022/6/13 11:05
 */

@Service
public class BMCgoodsServiceImpl extends ServiceImpl<BMCgoodsDao, BMCgoods> implements BMCgoodsService {

    @Autowired
    private BMCgoodsDao bmCgoodsDao;
    @Autowired
    private GoodimgService goodimgService;
    @Autowired
    private GoodcategoryService goodcategoryService;
    public List<BMCgoods> queryAll() {
        List<BMCgoods> bmCgoods = bmCgoodsDao.GetGoodsList();
        return bmCgoods;
    }

    public BMCgoods queryById(int id){
        BMCgoods bmCgoods = bmCgoodsDao.GetGoodsById(id);
        //查询照片列表
        QueryWrapper<good_imgs> qt = new QueryWrapper<good_imgs>();
        qt.eq("goodid",id);
        List<good_imgs> imglist = goodimgService.list(qt);
        //查询种类
        QueryWrapper<good_category> qw = new QueryWrapper<good_category>();
        qw.eq("goodid",id);
        good_category category = goodcategoryService.getOne(qw);
        bmCgoods.setImglist(imglist);
        bmCgoods.setGc(category);
        return bmCgoods;
    }

    @Override
    public int addgood(BMCgoods goods) {
        int i = bmCgoodsDao.AddGoods(goods);
        return i;
    }

    @Override
    public int updategood(BMCgoods goods) {
        int i = bmCgoodsDao.updateGoods(goods);
        return i;
    }

    @Override
    public int deletegood(int id) {
        int i = bmCgoodsDao.deleteGoods(id);
        return i;
    }




}
